home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / WINGUI / PATTERN.C < prev    next >
C/C++ Source or Header  |  1996-02-06  |  6KB  |  170 lines

  1. #include <stdio.h>
  2. #include "wingui\pattern.h"
  3. #include "wingui\wizunzip.h"
  4. #define UNZIP_INTERNAL
  5. #include "unzip.h"
  6. #include "wingui\helpids.h"
  7.  
  8.  
  9. char __based(__segname("STRINGS_TEXT")) szNoMatch[] =
  10.             "No entry matches the pattern!";
  11. /****************************************************************************
  12.  
  13.     FUNCTION: PatternSelectProc(HWND, unsigned, WPARAM, LPARAM)
  14.  
  15.     PURPOSE:  Processes messages for "Select Files by Pattern" dialog box
  16.  
  17.     MESSAGES:
  18.  
  19.     WM_INITDIALOG - initialize dialog box
  20.     WM_COMMAND    - Input received
  21.  
  22. ****************************************************************************/
  23.  
  24. #ifdef __BORLANDC__
  25. #pragma warn -par
  26. #endif
  27. BOOL WINAPI
  28. PatternSelectProc(HWND hwndDlg, WORD wMessage, WPARAM wParam, LPARAM lParam)
  29. {
  30. static HWND hSelect, hDeselect, hPattern;
  31. PSTR psLBEntry = NULL;  /* list box entry */
  32. PSTR psPatternBuf = NULL;   /* pattern collection   */
  33. DWORD cListItems;   /* no. items in listbox   */
  34. UINT Fname_Inx;      /* index into LB entry   */
  35. BOOL fSelect;      /* we're selecting if TRUE */
  36. int nPatternLength;   /* length of data in pattern edit window */
  37.  
  38.  
  39.    switch (wMessage) {
  40.    case WM_INITDIALOG:
  41.       hSelect = GetDlgItem(hwndDlg, IDOK);
  42.       hDeselect = GetDlgItem(hwndDlg, IDM_PATTERN_DESELECT);
  43.       hPattern = GetDlgItem(hwndDlg, IDM_PATTERN_PATTERN);
  44.       CenterDialog(GetParent(hwndDlg), hwndDlg);
  45.       return TRUE;
  46.    case WM_COMMAND:
  47.       switch (LOWORD(wParam)) {
  48.         case IDM_PATTERN_PATTERN:
  49.             if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
  50.                {
  51.                if ((nPatternLength = GetWindowTextLength(hPattern))==1)
  52.                   {
  53.          /* Enable or disable buttons depending on fullness of
  54.           * "Suffix" box.
  55.           */
  56.                   BOOL fButtonState = TRUE ;
  57.                   WinAssert(hSelect);
  58.                   EnableWindow(hSelect, fButtonState);
  59.                   WinAssert(hDeselect);
  60.                   EnableWindow(hDeselect, fButtonState);
  61.                   }
  62.                if (nPatternLength == 0)
  63.                   {
  64.                   BOOL fButtonState = FALSE;
  65.                   WinAssert(hSelect);
  66.                   EnableWindow(hSelect, fButtonState);
  67.                   WinAssert(hDeselect);
  68.                   EnableWindow(hDeselect, fButtonState);
  69.                   }
  70.                }
  71.             break;
  72.  
  73.       case IDOK: /* Select items using pattern */
  74.       case IDM_PATTERN_DESELECT:
  75.          fSelect = (BOOL)(LOWORD(wParam) == IDOK);
  76.          /* Be sure that listbox contains at least 1 item,
  77.           * that a pattern exists (is non-null), and
  78.           * that we can buffer them.
  79.           */
  80.          if ((cListItems = SendMessage(hWndList, (UINT)LB_GETCOUNT, 0, 0L)) != (UINT)LB_ERR &&
  81.               cListItems >= 1U &&
  82.             (nPatternLength = GetWindowTextLength(hPattern)) >= 1 &&
  83.             (psPatternBuf =   /* get a buffer   for the file name               */
  84.               (PSTR)LocalAlloc(LMEM_FIXED, nPatternLength+1)) != NULL &&
  85.            (psLBEntry =   /* get a buffer   for the file name               */
  86.               (PSTR)LocalAlloc(LMEM_FIXED, FILNAMSIZ+LONG_FORM_FNAME_INX)) != NULL &&
  87.             GetWindowText(hPattern, psPatternBuf, nPatternLength+1) > 0)
  88.          {
  89.          DWORD cItemsSelected = 0; /* no. "hits" during pattern search   */
  90.          UINT uLBInx;
  91.          PSTR psPattern;   /* points to any one pattern in buffer      */
  92.          static char DELIMS[] = " \t,"; /* delimiters, mostly whitespace */
  93.  
  94. #ifndef __BORLANDC__
  95.             _strlwr(psPatternBuf);   /* convert pattern to lower case   */
  96. #else
  97.             strlwr(psPatternBuf);   /* convert pattern to lower case   */
  98. #endif
  99.             Fname_Inx = (UINT)(uf.fFormatLong ? LONG_FORM_FNAME_INX : SHORT_FORM_FNAME_INX);
  100.             /* march through list of patterns in edit field            */
  101. #if (defined MSC) && (!defined WIN32)
  102.             for (psPattern = strtok(psPatternBuf, DELIMS);
  103.                 psPattern != NULL; psPattern = strtok(NULL, DELIMS))
  104. #else
  105.             for (psPattern = (PSTR)strtok(psPatternBuf, DELIMS);
  106.                 psPattern != NULL; psPattern = (PSTR)strtok(NULL, DELIMS))
  107. #endif
  108.             {
  109.  
  110.                /* March thru listbox matching the complete path with every entry.
  111.                 * Note: unzip's match() function probably won't work for national
  112.                 * characters above the ASCII range.
  113.                 */
  114.                for (uLBInx = 0; uLBInx < cListItems; uLBInx++)
  115.                {
  116.                   /* Retrieve listbox entry                        */
  117.                    if (SendMessage(hWndList, LB_GETTEXT, uLBInx, (LPARAM)((LPSTR)psLBEntry)) >
  118.                      (LRESULT)Fname_Inx)
  119.                   {
  120. #ifndef __BORLANDC__
  121.                      _strlwr(&psLBEntry[Fname_Inx]); /* convert filename to lower case */
  122. #else
  123.                      strlwr(&psLBEntry[Fname_Inx]); /* convert filename to lower case */
  124. #endif
  125.                      /* Use UnZip's match() function                  */
  126.                      /* MW: verify that we really want to ignore case */
  127.                      if (match(&psLBEntry[Fname_Inx], psPattern, TRUE))
  128.                      {
  129.                         SendMessage(hWndList, LB_SETSEL, (WPARAM)fSelect, 
  130.                                  MAKELPARAM(uLBInx,0));
  131.                         cItemsSelected++;
  132.                      }
  133.                   }
  134.                }
  135.             }
  136.             if (!cItemsSelected)   /* If no pattern match               */
  137.             {
  138.                MessageBox(hwndDlg, szNoMatch, szAppName, MB_OK | MB_ICONASTERISK);
  139.             }
  140.             else /* one or more items were selected */
  141.             {
  142.                UpdateButtons(hWndMain); /* turn main push buttons on or off */
  143.             }
  144.          }
  145.          if (psLBEntry)
  146.             LocalFree((HLOCAL)psLBEntry);
  147.  
  148.          if (psPatternBuf)
  149.             LocalFree((HLOCAL)psPatternBuf);
  150.          break;
  151.       case IDCANCEL:
  152.          PostMessage(hwndDlg, WM_CLOSE, 0, 0L);
  153.          break;
  154.       case IDM_PATTERN_HELP:
  155.             WinHelp(hwndDlg,szHelpFileName,HELP_CONTEXT, (DWORD)(HELPID_SELECT_BY_PATTERN));
  156.          break;
  157.       }
  158.       return TRUE;
  159.    case WM_CLOSE:
  160.       DestroyWindow(hwndDlg);
  161.       hPatternSelectDlg = 0; /* flag dialog inactive   */
  162.       return TRUE;
  163.    }
  164.    return FALSE;
  165. }
  166. #ifdef __BORLANDC__
  167. #pragma warn .par
  168. #endif
  169.  
  170.